package h0906;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description 两整数之和
 * @date 2024/9/6 21:12
 */
public class TwoIntegerAdd {
    public static void main(String[] args) {
        int a = -1;
        int b = -2;
        System.out.println(getSum(a, b));
    }

    public static int getSum(int a, int b) {
        int sum = a;
        int carry; //进位
        while (b != 0) { //当进位为0就跳出循环
            sum = a ^ b;
            carry = a & b;
            a = sum;
            b = carry << 1;
        }
        return sum;
    }
}
